<?php
function checkOrderPrivate()
{
$d=date("Y-m-d H:i:s");
$c=mysql_query("SELECT *  FROM sme_order WHERE DATE_ADD( orderadddate, INTERVAL 7 DAY ) <= '$d' AND  status = '1'");
if(mysql_num_rows($c))
{
$sqlOutdate="UPDATE sme_order SET status = '6' ,orderactiondate='".date("Y-m-d H:i:s")."' WHERE DATE_ADD( orderadddate, INTERVAL 7 DAY ) <= '$d'  AND status = '1'";
$sqlup=array();
$sqlreturn="SELECT productId, SUM(quantity)
FROM sme_order, sme_orderdetail
WHERE DATE_ADD( orderadddate, INTERVAL 7
DAY ) <= '$d'
AND sme_order.orderId = sme_orderdetail.orderId
AND sme_order.status = '1'
GROUP BY productId";
$qrt=mysql_query($sqlreturn); $i=0;
while($rs=mysql_fetch_array($qrt))
{
	$q=mysql_fetch_array(mysql_query("SELECT quantity FROM sme_product  WHERE productId='".$rs[0]."'"));
	$rtpro=$q[0]+$rs[1];
	$sqlup[$i]="UPDATE sme_product SET quantity = '$rtpro'  WHERE sme_product.productId ='".$rs[0]."' LIMIT 1 ";
	$i++;
}
foreach($sqlup as $a)	{mysql_query($a);	}	
mysql_query($sqlOutdate);
}
}
?>